home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / web / noweb / contrib / conrado / algoritmos.sty (.txt) < prev    next >
LaTeX Document  |  1995-02-24  |  6KB  |  134 lines

  1. \catcode`@=11
  2. % \listofalgorithms
  3. % this macro is like \listoffigures or \listoftables; it prepares a
  4. % list of algorithms/programs using an auxiliary file (.lop)
  5. % CUSTOMIZATION: the banner of the list is a string defined by \listalgorithmsname;
  6. % the default value is ``List of Algorithms''
  7. \def\listofalgorithms{\@restonecolfalse\if@twocolumn\@restonecoltrue\onecolumn
  8.   \fi\chapter*{\listalgorithmsname\@mkboth
  9.    {\uppercase{\listalgorithmsname}}{\uppercase{\listalgorithmsname}}}
  10.    \addcontentsline{toc}{chapter}{\listalgorithmsname}
  11.    {\ssp\@starttoc{lop}}\if@restonecol
  12.   \twocolumn\fi}
  13. \let\l@algorithm\l@figure
  14. \def\listalgorithmsname{List of Algorithms}
  15. % \begin{algorithm} ... \end{algorithm} 
  16. % the 'algorithm' environment encloses a float object (like figure or table)
  17. % algorithm's get their own numbering; captions begin with
  18. % ``Algorithm'', then the number, and then the text;  
  19. % and there is an entry in the .lop file for each 'algorithm'
  20. % CUSTOMIZATION: the first word in a caption is given by \algorithmname
  21. \newcounter{algorithm}
  22. \def\thealgorithm{\@arabic\c@algorithm}
  23. \def\fps@algorithm{tbp}
  24. \def\ftype@algorithm{4}
  25. \def\ext@algorithm{lop}
  26. \def\fnum@algorithm{\algorithmname\ \thealgorithm}
  27. \def\algorithm{\@float{algorithm}}
  28. \def\endalgorithm{\end@float}
  29. \@namedef{algorithm*}{\@dblfloat{algorithm}}
  30. \@namedef{endalgorithm*}{\end@dblalgorithm}
  31. \def\algorithmname{Algorithm}
  32. % \begin{code} ... \end{code} 
  33. % this environment is a slight modification of the tabbing environment.
  34. % the specific characteristics are:
  35. %  0) it has a parameter from xref information
  36. %  1) there is a small skip between the paragraph above and the first
  37. %  line of the code.
  38. %  2) a rule is drawn at the beginning and at the end of the code.
  39. %  3) all lines are typeset in math mode
  40. %  4) |<something>| prints <something> in \rm if issued inside math
  41. %      mode (for instance, inside this environment);  
  42. %     and in \sl if issued outside math mode
  43. %  5) _ can be used instead of \_ inside the code environments and in
  44. %     text; it produces subscripts in math mode as usual
  45. %  6) <return>'s are obeyed; if you want to break lines in the source
  46. %  but not in the final document terminate the line with a comment char %
  47. %  7) you can leave a blank line using \\
  48. % it also introduces a command \numberlines that has no effect in this
  49. % environment, but it has in the *-form of code
  50. % CUST: \algosep and \algoruleheight are the length parameters that
  51. % give the amount of skip between the previous paragraph and the
  52. % beginning of code, and the width of the rule.
  53. % Both have default value 0pt. \algofontsize allows changing the font size
  54. % of the text written inside a code environment. The default is \footnotesize
  55. \def\numberlines{}
  56. \newlength{\algosep}
  57. \newlength{\algoruleheight}
  58. \def\rulecode{\rule{\textwidth}{\algoruleheight}}
  59. \def\sepcode{\vspace{\algosep}}
  60. \def\algofontsize{\footnotesize}
  61. \newif\ifinsidecode
  62. \insidecodefalse
  63. \def\@programcr{$\@tabcr$}
  64. {\catcode`\;=\active \gdef;{\semicolon\;}}
  65. \mathchardef\semicolon="603B
  66. \catcode`\_=\active \gdef_{\ifinsidecode\_\else\ifmmode\sb\else\_\fi\fi}
  67. \catcode`\|=12\relax
  68. \def\origbar{|}
  69. \catcode`\|=\active
  70. \def|{\ifx\@sharp\relax\origbar\else\@dovar\fi}
  71. \def\@dovar#1#2|{#1\ifmmode{\mbox{\rm #2}}\else{\sl #2}\fi} 
  72. \def\@tabcommandson{% activate tabbing commands:
  73.     % \tab sets a tab stop and adds one to the margin tab:
  74.     \def\tab{$\=\+$}
  75.     % Must finish current field before testing if at margin:
  76.     \def\@finishfield{\@stopfield\@addfield\@startfield}
  77.     % \untab removes one tab stop and moves left if at the beginning of a line:
  78.     \def\untab{$\@finishfield\@ifatmargin\@ltab\else\relax\fi\-$}
  79.     % \@marginspace adds an extra space unless there is no text on the line:
  80.     \def\@marginspace{$\@finishfield$\@ifatmargin\relax\else\ \fi}}
  81. \def\@tabcommandsoff{% deactivate tabbing commands:
  82.     \let\tab=\relax
  83.     \let\@finishfield=\relax
  84.     \let\untab=\relax
  85.     \let\@marginspace=\ % never at margin thus always a space
  86. \@tabcommandsoff
  87. \def\code#1{\par\sepcode
  88. \noindent\rulecode\algofontsize\numberlines\insidecodetrue
  89. \@tabcommandson \obeycr
  90. \lineskip \z@\let\>\@rtab\let\<\@ltab\let\=\@settab
  91.      \let\+\@tabplus\let\-\@tabminus\let\t\tab\let\u\untab
  92. \let\\=\@programcr 
  93. \global\@hightab\@firsttab \global\@nxttabmar\@firsttab
  94. \dimen\@firsttab\@totalleftmargin \global\@tabpush0
  95. \global\@rjfieldfalse \trivlist
  96. \item[]\if@minipage\else\vskip\parskip\fi
  97. \setbox\@tabfbox\hbox{\rlap{\indent\hskip\@totalleftmargin
  98. \the\everypar}}\def\@itemfudge{\box\@tabfbox}\@startline\ignorespaces
  99. $\@gobblecr
  100. \def\endcode{$\@stopline\ifnum\@tabpush > 0 \@badpoptabs
  101. \fi\endtrivlist\noindent\@tabcommandsoff
  102. \rulecode
  103. \sepcode
  104. % \begin{code*} ... \end{code*} 
  105. % the *-form of code numbers sequentially each line of the code (lines
  106. % are separated by \\'s)
  107. % CUST: the label of each line can be easily changed, by redefining
  108. % the macro \codelinelabel and/or the macro \thecodeline; the counter
  109. % is codeline.
  110. \newcounter{codeline}
  111. \def\thecodeline{\arabic{codeline}}
  112. \def\codelinelabel{\thecodeline.\ \ }
  113. \@namedef{code*}{\def\numberlines{\setcounter{codeline}{0}
  114. \def\@stopline{\addtocounter{codeline}{1}
  115. \unskip\@stopfield\if@rjfield \global\@rjfieldfalse
  116.    \@tempdima\@totalleftmargin \advance\@tempdima\linewidth
  117. \hbox to\@tempdima{\@itemfudge\codelinelabel\hskip\dimen\@curtabmar
  118.    \box\@curline\hfil\box\@curfield}\else\@addfield
  119.    \hbox{\@itemfudge\codelinelabel\hskip\dimen\@curtabmar\box\@curline}\fi}
  120. }\code}                                 
  121. \@namedef{endcode*}{\endcode}
  122. \catcode`@=12
  123. % \begin{cntcode} ... \end{cntcode}
  124. % a slight variation of the code environment, cntcode centers its
  125. % contents; it should be used only if there is no page break in
  126. % the middle of the code; that means that its usefulness is limited to
  127. % small chunks of code, specifications, short declarations, ...
  128. \newlength{\codewidth}
  129. \setlength{\codewidth}{0.7\textwidth}
  130. \newenvironment{cntcode}{\def\sepcode{}\def\rulecode{}\centering
  131. \begin{minipage}[t]{\codewidth}
  132. \begin{code}}{\end{code}\end{minipage}
  133. \par}
  134.